<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>查看用户</title>
</head>
<body>
<jsp:include page="/incloud/header.jsp" />
<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <jsp:include page="/incloud/sidebar.jsp" />
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">用户列表</h2>
            </div>
        </div>
        <section class="no-padding-bottom">
            <div class="title">
                <form class="form-inline">
                    <div class="form-group">
                        <label for="inlineFormInput" class="sr-only">Name</label>
                        <input id="inlineFormInput" value="${realName}" type="text" placeholder="按名字查找" class="mr-sm-3 form-control">
                    </div>
                    <div class="form-group">
                        <input type="button" onclick="search()" value="查询" class="btn btn-primary">
                    </div>
                </form>

            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>简介</th>
                        <th>操作</th>
                        <th>加关注</th>
                    </tr>
                    </thead>
                    <tbody>

                    <c:forEach items="${userList}" var="user" varStatus="status">
                    <tr>
                        <th scope="row">${user.id}</th>
                        <td>${user.realName}</td>
                        <td>${user.gender == 0?"女":"男"}</td>
                        <td>${user.age}</td>
                        <td>${user.info}</td>
                        <td>
                            <input type="submit" onclick="lookInfo(${user.id},${user.isSecret})" value="详细信息" class="btn-xs btn-primary userDetail">
                        </td>
                        <td>
                            <input type="checkbox" ${user.id == loginUser.id?"disabled='disabled'":""} onclick="fcous(${user.id })" ${fn:contains(fansList,user.id )?"checked":""} value="" class="checkbox-template">
                        </td>
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <c:if test="${pageCount > 0}">
                        <li>
                            <a href="javascript:0;" onclick="pre(${cureePage})" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach begin="1" end="${pageCount}" varStatus="status">
                        <li><a href="/user/findUser?cureePage=${status.count}&realName=${realName}">${status.count}</a></li>
                        </c:forEach>
                        <li>
                            <a href="javascript:0;" onclick="next(${cureePage})" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                        </c:if>
                    </ul>
                </nav>
            </div>
        </section>

        <jsp:include page="/incloud/footer.jsp" />
    </div>
</div>

<!-- JavaScript files-->


<script type="text/javascript">
    //添加/取消关注
    function fcous(id) {
        if(id == ${loginUser.id}){
            return;
        }
        $.get("/user/Attention?id="+id);
    }
    //查看用户信息
    function lookInfo(id,isSecret) {
        if(isSecret == 0 && id != ${loginUser.id}){
            layer.msg("私密模式无法查看");
            return;
        }
        location.href="/user/detail?id="+id;
    }
    //模糊查询用户列表信息
    function search() {
        var searchName = $("#inlineFormInput").val();
        location.href = "/user/findUser?cureePage=1&realName="+searchName;
    }
    //上一页
	function pre(cureePage){
        if(cureePage - 1 < 1){
            layer.msg("已经是第一页了")
            return;
        }
        location.href = "/user/findUser?cureePage="+(cureePage-1)+"&realName="+$("#inlineFormInput").val();
    }
    //下一页
    function next(cureePage){
        if(cureePage +1 > ${pageCount}){
            layer.msg("已经是最后一页了")
            return;
        }
        location.href = "/user/findUser?cureePage="+(cureePage+1)+"&realName="+$("#inlineFormInput").val();
    }
	$(function(){
        $("#avatar").click(function () {
            location.href = "/user/detail?id=${loginUser.id}";
        })
		
		//用户列表，查看详情，通过class名字userDetail来找
		$("#userDetail").click(function () {
		    console.log("你点击了用户详情");
		    window.location.href = '/html/user_detail.jsp'
		});
		
		$(".table").find("input[type='checkbox']").on("click",function () {
		    if($(this).prop("checked")){
		        layer.msg("关注成功")
		    }else{
		        layer.msg("取关成功")
		
		    }
		
		})
		
	})
</script>
</body>
</html>